package demo1;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.stream.Collector;

public class TestPriorityQueue {
    public static void main1(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(10);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        System.out.println(priorityQueue.peek());
        System.out.println(priorityQueue.isEmpty());
    }

    public static void main2(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        student student = new student();
        priorityQueue.offer(student.age);
        //priorityQueue.offer(new student());
        //priorityQueue.offer(null);
        System.out.println(priorityQueue.peek());
    }

    public static void main3(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(3);
        arrayList.add(4);
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(arrayList);
        System.out.println(priorityQueue.peek());
    }

    public static void main(String[] args) {
        Compare compare = new Compare();
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(compare);
        priorityQueue.offer(10);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        System.out.println(priorityQueue.peek());//输出：10
    }
    public static void main4(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        priorityQueue.offer(10);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        System.out.println(priorityQueue.peek());//输出：10
    }
}
class Compare implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
class student {
    public int age;
}

